//package com.example.unique.ui.slideshow
//
//
//import android.os.Bundle
//
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.fragment.app.Fragment
//
//import com.example.unique.databinding.FragmentSlideshowBinding
//
//
//class SlideshowFragment : Fragment() {
//
//    private var _binding: FragmentSlideshowBinding? = null
//    private val binding get() = _binding!!
//
//
//    override fun onCreateView(
//        inflater: LayoutInflater,
//        container: ViewGroup?,
//        savedInstanceState: Bundle?
//    ): View {
//
//        _binding = FragmentSlideshowBinding.inflate(inflater, container, false)
//        val root: View = binding.root
//
//        return root
//    }
//
//}
package com.example.unique.ui.slideshow

import android.content.SharedPreferences
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.example.unique.R
import com.example.unique.databinding.FragmentSlideshowBinding

class SlideshowFragment : Fragment() {

    private var _binding: FragmentSlideshowBinding? = null
    private val binding get() = _binding!!

    // 获取 ViewModel
    private val slideshowViewModel: SlideshowViewModel by viewModels()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        // 初始化 ViewBinding
        _binding = FragmentSlideshowBinding.inflate(inflater, container, false)
        val root: View = binding.root

        // 初始化并设置主题开关
        binding.themeSwitch.isChecked = slideshowViewModel.isDarkMode.value ?: false
        binding.themeSwitch.setOnCheckedChangeListener { _, isChecked ->
            slideshowViewModel.setDarkMode(isChecked)
        }

        // 显示应用版本
        binding.versionTextView.text = getString(R.string.version_text, "1.0")

        // 检查更新按钮
        binding.updateButton.setOnClickListener {
            Toast.makeText(context, "Checking for updates...", Toast.LENGTH_SHORT).show()
        }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

